<template>
  <div class="report-container">
    <div @click="openDialog()">举报</div>
    <el-dialog title="举报" :visible.sync="dialogVisible" width="28%">
      <div class="report-box">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-radio-group v-model="ruleForm.reason">
            <div
              v-for="(item, index) in reportArray"
              :key="index"
              class="check-item"
            >
              <div>
                <el-radio
                  :label="item.dictLabel"
                  size="medium"
                  style="font-size: 30px"
                  >{{ item.dictLabel }}</el-radio
                >
              </div>
            </div>
          </el-radio-group>
          <el-form-item
            label="举报内容"
            prop="content"
            style="margin-top: 20px"
          >
            <el-input type="textarea" v-model="ruleForm.content"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')"
              >提交举报</el-button
            >
            <el-button @click="resetForm('ruleForm')">取消</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span> -->
    </el-dialog>
  </div>
</template>

<script>
import { reportPost } from "@/api/szpt/report.js";
export default {
  data() {
    return {
      dialogVisible: false,
      reportArray: [],
      ruleForm: {
        type: "REPORT",
        entityId: this.$route.query.id,
        entityType: "com.ruoyi.szpt.sz_post.domain.SzPost",
        content: "",
        reason: "",
      },
      rules: {
        content: [
          { required: true, message: "请填写举报内容...", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.cities.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.cities.length;
    },
    openDialog() {
      this.getDicts("report_status_post").then((response) => {
        this.reportArray = response.data;
        this.dialogVisible = true;
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$modal.loading("玩命加载中...");
          reportPost(this.ruleForm)
            .then((resp) => {
              if (resp.code === 200) {
                this.$message.success("举报成功！");
                this.ruleForm.content = "";
              }
              this.$modal.closeLoading();
              this.dialogVisible = false;
            })
            .catch((err) => {
              this.$message.error("举报失败，请稍后重试！");
              this.$modal.closeLoading();
              this.dialogVisible = false;
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dialogVisible = false;
    },
  },
};
</script>

<style lang="scss">
.report-container {
  width: 100%;
  height: 40px;
  line-height: 40px;
  padding: 0 30px;
  display: flex;
  justify-content: flex-end;
  color: #666;
  background-color: #fff;
  margin-top: 10px;
  margin-bottom: 10px;
  cursor: pointer;
}
.report-container:hover {
  color: red;
}
.report-box {
  width: 100%;
  height: auto;
  .check-item {
    width: 100%;
    height: 40px;
    font-size: 20px;
    line-height: 40px;
    padding: 10 50px;
    margin-top: 10px;
    margin-bottom: 10px;
    .el-radio__label {
      font-size: 18px !important;
    }
  }
}
</style>
